﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using LPV_POS;
using System.Resources;
using System.Globalization;


public partial class mh_thaydoingaylamviec : DevExpress.XtraEditors.XtraForm
{
    CultureInfo culture;

    #region "Muti language"

    private void SetLanguage_banhang(string cultureName)
    {
        try
        {
            culture = CultureInfo.CreateSpecificCulture(cultureName);
            ResourceManager rm = new ResourceManager("LPV_POS.Muti_language.MyResource", typeof(mh_thaydoingaylamviec).Assembly);
            bton_ngay_cong.Text = rm.GetString("ngaycong", culture);
            bton_thang_cong.Text = rm.GetString("thangcong", culture);
            bton_nam_cong.Text = rm.GetString("namcong", culture);
            bton_ngay_tru.Text = rm.GetString("ngaytru", culture);
            bton_thang_tru.Text = rm.GetString("thangtru", culture);
            bton_nam_tru.Text = rm.GetString("namtru", culture);
            bton_thuchien_1.Text = rm.GetString("luu", culture);
            bton_thoat_1.Text = rm.GetString("thoat", culture);
            this.Name = rm.GetString("thaydoingaylamviec", culture);

        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.ToString(), "Note");
        }

    }

    #endregion

    public mh_thaydoingaylamviec()
    {
        InitializeComponent();
        culture = CultureInfo.CurrentCulture;
    }

    private void mh_thaydoingaylamviec_Load(object sender, EventArgs e)
    {

        cpublic ocpublic = new cpublic();
        string str_lang = ocpublic.Registry_Get("mh_main_lang");
        if (str_lang == "")
            str_lang = "vi-VN";
        SetLanguage_banhang(str_lang);

        date_ngaythangnam.DateTime = DateTime.Today;
        DataTable tbTMP = new thuvien().SP_SelectDataTable("sp_BH_CAU_HINH",
                                                    new string[] { "@flag" },
                                                    new object[] { 4 });
        if (tbTMP.Select().Length > 0)
            if (tbTMP.Rows[0]["NGAY_LAM_VIEC"] + "" != "")
                date_ngaythangnam.DateTime = (DateTime)tbTMP.Rows[0]["NGAY_LAM_VIEC"];
    }
    //---------21/06/2012----------------------
    #region " Lấy giá trị : True/false từ field NGAY_LAM_VIEC_LA_NGAY_HE_THONG"
    DataTable tbNGAYLAMVIEC = null;
    private void get_TrueFalseNGAY_LAM_VIEC()
    {
        string sSQL = "SELECT NGAY_LAM_VIEC_LA_NGAY_HE_THONG FROM BH_CAU_HINH";
        tbNGAYLAMVIEC = new thuvien().SP_SelectDataTable("SP_EXECUTESQL", new string[] { "@sSQL" }, new object[] { sSQL });
    }
    #endregion
    //---------21/06/2012----------------------
    private void bton_ngay_cong_Click(object sender, EventArgs e)
    {
        date_ngaythangnam.DateTime = date_ngaythangnam.DateTime.AddDays(1);
    }

    private void bton_thang_cong_Click(object sender, EventArgs e)
    {
        date_ngaythangnam.DateTime = date_ngaythangnam.DateTime.AddMonths(1);
    }

    private void bton_nam_cong_Click(object sender, EventArgs e)
    {
        date_ngaythangnam.DateTime = date_ngaythangnam.DateTime.AddYears(1);
    }

    private void bton_ngay_tru_Click(object sender, EventArgs e)
    {
        date_ngaythangnam.DateTime = date_ngaythangnam.DateTime.AddDays(-1);
    }

    private void bton_thang_tru_Click(object sender, EventArgs e)
    {
        date_ngaythangnam.DateTime = date_ngaythangnam.DateTime.AddMonths(-1);
    }

    private void bton_nam_tru_Click(object sender, EventArgs e)
    {
        date_ngaythangnam.DateTime = date_ngaythangnam.DateTime.AddYears(-1);
    }

    private void bton_thoat_Click(object sender, EventArgs e)
    {
        this.Close();
    }

    private void bton_luu_Click(object sender, EventArgs e)
    {
        //    ---Variable.ngay_lamviec = date_ngaythangnam.DateTime;
        //---------18/06/2012-----------------------------------------
        this.get_TrueFalseNGAY_LAM_VIEC();
        if (tbNGAYLAMVIEC != null && (tbNGAYLAMVIEC.Rows[0]["NGAY_LAM_VIEC_LA_NGAY_HE_THONG"] + "") == "True")
            Variable.ngay_lamviec = Variable.ngay_gio_hienhanh;
        else
            if ((tbNGAYLAMVIEC.Rows[0]["NGAY_LAM_VIEC_LA_NGAY_HE_THONG"] + "") != "True")
                Variable.ngay_lamviec = date_ngaythangnam.DateTime;
        //---------18/06/2012-----------------------------------------
        new thuvien().SP_Update("sp_BH_CAU_HINH",
                                new string[] { "@flag", "@NGAY_LAM_VIEC" },
                                new object[] { 5, date_ngaythangnam.DateTime });//----------18/06/2012-------------
        MessageBox.Show("Lưu thành công");
    }

    private void lbel_calendar_Click(object sender, EventArgs e)
    {
        date_ngaythangnam.ShowPopup();
    }
}
